<?php
namespace App\Hospital\Controllers;

use App\Exceptions\Grid;
use Dcat\Admin\Admin;
use Dcat\Admin\Http\Controllers\AdminController as Controller;
use Dcat\Admin\Layout\Content;

class AdminController extends Controller
{
    public function dialog(Grid $grid, $className, $columnLabel, $label, $dialogUrl = null)
    {
        if (empty($dialogUrl)) {
            $dialogUrl = $this->dialogUrl;
        }
        $js = <<<EOD
$('.$className').click(function () {
    var id = $(this).data('id');
    layer.open({
        type: 2,
        title: '$columnLabel',
        area: ['80%', '90%'],
        content: '$dialogUrl?id='+id,
    });
});
EOD;
        \Admin::script($js);
        $grid->column($className, $columnLabel)->display(function () use ($className, $label) {
            return sprintf('<a href="###" class="%s" data-id="%d">&nbsp;&nbsp;&nbsp;&nbsp;%s</a>', $className, $this->id, $label);
        });
    }
}
